<template>
  <div class="page-container flex">
    <sidebar></sidebar>
    <div class="flex flex-1 flex-column" style="width: 0">
      <toolbar :refresh-page="refreshPage" @lock="changelock(true)"></toolbar>
      <router-view v-slot="{ Component, route }">
        <transition name="page-transition" mode="out-in">
          <div class="view-container flex-1" :key="route.path + pageKey" id="page-warpper">
            <div class="flex-1" style="position: relative">
              <component :is="Component" />
            </div>
            <web-footer />
          </div>
        </transition>
      </router-view>
    </div>
    <lock :lock="isLock" @unlock="changelock(false)" />
  </div>
</template>

<script setup lang="ts">
import sidebar from '@/components/sidebar/index.vue';
import toolbar from '@/components/toolbar/index.vue';
import lock from '@/components/lock-view/index.vue';
import webFooter from '@/components/webfooter/index.vue';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { IS_LOCK } from '@/utils/constant';

const isLock = ref(false);
const router = useRouter();
const pageKey = ref(0);

isLock.value = localStorage.getItem(IS_LOCK) === '1';

function refreshPage() {
  router.push({ name: router.currentRoute.value.name });
  pageKey.value++;
}

function changelock(value) {
  isLock.value = value;
  localStorage.setItem(IS_LOCK, isLock.value ? '1' : '0');
}
</script>

<style scoped lang="scss">
.view-container {
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.page-transition-enter-active,
.page-transition-leave-active {
  transition: opacity 200ms, transform 500ms;
}
.page-transition-enter-from,
.page-transition-leave-to {
  opacity: 0;
}
.page-transition-enter-from {
  transform: translateY(40px);
}
.page-transition-leave-to {
  transform: translateX(40px);
}
</style>
